home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 April / macformat-023.iso / Shareware City / Developers / inc-dec / source / lib / fss_utl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-18  |  4.2 KB  |  186 lines  |  [TEXT/KAHL]

  1. /* ==========================================
  2.  
  3.     fss_utl.c    
  4.  
  5.     Copyright (c) 1993,1994 Newport Software Development
  6.     
  7.     You may distribute unmodified copies of this file for
  8.     noncommercial purposes.  You may use this file as a
  9.     reference when writing your own nShell(tm) commands.
  10.     
  11.     All other rights are reserved.
  12.         
  13.    ========================================== */
  14.  
  15. #include <GestaltEqu.h>
  16.  
  17. #include "fss_utl.proto.h"
  18.  
  19. /* ========================================== */
  20.  
  21. // test this once and store it away somewhere safe
  22.  
  23. int fss_test( void )
  24. {
  25.     long    response;
  26.     
  27.     if ( Gestalt( gestaltFSAttr, &response ) )
  28.         return(false);
  29.         
  30.     if ( response & ( 1L << gestaltHasFSSpecCalls ) )
  31.         return(true);
  32.     else
  33.         return(false);
  34. }
  35.  
  36. /* ========================================== */
  37.  
  38. // open data fork using FSSpec
  39.  
  40. OSErr fss_OpenDF(int gotFSSpec, const FSSpec *spec, char permission, short *refNum)
  41. {
  42.     OSErr            result;
  43.     HParamBlockRec    pb;
  44.  
  45.     if (gotFSSpec)
  46.         return (FSpOpenDF(spec, permission, refNum));
  47.     else {
  48.         pb.ioParam.ioVRefNum = spec->vRefNum;
  49.         pb.fileParam.ioDirID = spec->parID;
  50.         pb.ioParam.ioNamePtr = (StringPtr) &(spec->name);
  51.         pb.ioParam.ioVersNum = 0;
  52.         pb.ioParam.ioPermssn = permission;
  53.         pb.ioParam.ioMisc = nil;
  54.         result = PBHOpenSync(&pb);
  55.         *refNum = pb.ioParam.ioRefNum;
  56.         return (result);
  57.         }
  58. }
  59.  
  60. /* ========================================== */
  61.  
  62. OSErr fss_OpenRF(int gotFSSpec, const FSSpec *spec, char permission, short *refNum)
  63. {
  64.     OSErr            result;
  65.     HParamBlockRec    pb;
  66.  
  67.     if (gotFSSpec)
  68.         return (FSpOpenRF(spec, permission, refNum));
  69.     else {
  70.         pb.ioParam.ioVRefNum = spec->vRefNum;
  71.         pb.fileParam.ioDirID = spec->parID;
  72.         pb.ioParam.ioNamePtr = (StringPtr) &(spec->name);
  73.         pb.ioParam.ioVersNum = 0;
  74.         pb.ioParam.ioPermssn = permission;
  75.         pb.ioParam.ioMisc = nil;
  76.         result = PBHOpenRFSync(&pb);
  77.         *refNum = pb.ioParam.ioRefNum;
  78.         return (result);
  79.         }
  80. }
  81.  
  82. /* ========================================== */
  83.  
  84. // read the finder information block
  85.  
  86. OSErr fss_GetFInfo(int gotFSSpec, const FSSpec *spec, FInfo *fndrInfo)
  87. {
  88.     OSErr            result;
  89.     HParamBlockRec    pb;
  90.  
  91.     if (gotFSSpec)
  92.         return (FSpGetFInfo(spec, fndrInfo));
  93.     else {
  94.         pb.fileParam.ioVRefNum = spec->vRefNum;
  95.         pb.fileParam.ioDirID = spec->parID;
  96.         pb.fileParam.ioNamePtr = (StringPtr) &(spec->name);
  97.         pb.fileParam.ioFVersNum = 0;
  98.         pb.fileParam.ioFDirIndex = 0;
  99.         result = PBHGetFInfoSync(&pb);
  100.         *fndrInfo = pb.fileParam.ioFlFndrInfo;
  101.         return (result);
  102.         }
  103. }
  104.  
  105. /* ========================================== */
  106.  
  107. OSErr fss_SetFInfo(int gotFSSpec, const FSSpec *spec, const FInfo *fndrInfo)
  108. {
  109.     OSErr            result;
  110.     HParamBlockRec    pb;
  111.  
  112.     if (gotFSSpec)
  113.         return (FSpSetFInfo(spec, fndrInfo));
  114.     else {
  115.         pb.fileParam.ioVRefNum = spec->vRefNum;
  116.         pb.fileParam.ioDirID = spec->parID;
  117.         pb.fileParam.ioNamePtr = (StringPtr) &(spec->name);
  118.         pb.fileParam.ioFVersNum = 0;
  119.         pb.fileParam.ioFDirIndex = 0;
  120.         result = PBHGetFInfoSync(&pb);
  121.         if (!result) {
  122.             pb.fileParam.ioFlFndrInfo = *fndrInfo;
  123.             pb.fileParam.ioDirID = spec->parID;
  124.             result = PBHSetFInfoSync(&pb);
  125.             }
  126.         return (result);
  127.         }
  128. }
  129.  
  130. /* ========================================== */
  131.  
  132. OSErr fss_to_DirID(const FSSpec *spec, long *theDirID, Boolean *isDirectory)
  133. {
  134.     CInfoPBRec pb;
  135.     OSErr error;
  136.  
  137.     pb.hFileInfo.ioNamePtr = (StringPtr)spec->name;
  138.     pb.hFileInfo.ioVRefNum = spec->vRefNum;
  139.     pb.hFileInfo.ioDirID = spec->parID;
  140.     pb.hFileInfo.ioFDirIndex = 0;
  141.     error = PBGetCatInfoSync(&pb);
  142.     
  143.     if (error) {
  144.         *theDirID = 0;
  145.         *isDirectory = 0;
  146.         }
  147.     else {
  148.         *theDirID = pb.hFileInfo.ioDirID;
  149.         *isDirectory = (pb.hFileInfo.ioFlAttrib & 0x10) != 0;
  150.         }
  151.         
  152.     return (error);
  153. }
  154.  
  155. /* ========================================== */
  156.  
  157. // advance the date of a parent directory, so the finder knows to redraw etc.
  158.  
  159. OSErr fss_wake_parent(const FSSpec *spec)
  160. {
  161.     CInfoPBRec pb;
  162.     OSErr error;
  163.     unsigned long old_secs;
  164.     unsigned long new_secs;
  165.  
  166.     pb.hFileInfo.ioNamePtr = nil;
  167.     pb.hFileInfo.ioVRefNum = spec->vRefNum;
  168.     pb.hFileInfo.ioDirID = spec->parID;
  169.     pb.hFileInfo.ioFDirIndex = 0;
  170.     
  171.     error = PBGetCatInfoSync(&pb);
  172.     GetDateTime(&new_secs);
  173.     
  174.     if (error == noErr) {
  175.         old_secs = pb.hFileInfo.ioFlMdDat;
  176.         if (old_secs < new_secs)
  177.             pb.hFileInfo.ioFlMdDat = new_secs;
  178.         else
  179.             pb.hFileInfo.ioFlMdDat++;
  180.         pb.hFileInfo.ioDirID = spec->parID;
  181.         error = PBSetCatInfoSync(&pb);
  182.         }
  183.         
  184.     return (error);
  185. }
  186.